<?php 
	include_once("common/init.php");
	if($_REQUEST["type"]=="logout"){
		session_destroy();
		session_start();
		urlMsg("退出成功","login.php");
		die;
	}
	if ($_POST) {
			$rsRow = db_get_row("select * from user where status=0 and account='". $_POST["account"] ."'");
			
			$code=$_POST['code'];
			if(strcasecmp($code, $_SESSION['captcha'])!=0){
				goBakMsg("验证码有误！");
			}
			
			if ($rsRow['password'] == $_POST["password"] ){
				$_SESSION["id"]=$rsRow['id'];
				$_SESSION['account']=$rsRow['account'];
				urlMsg("登录成功","index.php");
				die;
			} else {
				goBakMsg("账号不存在或密码错误或被禁用");
			}
			
	}

?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>用户登录界面</title>
  <link rel="stylesheet" href="./Public/css/login.css">
</head>
<body>
	<div id="root" style="background:url(./Public/images/bg.jpeg) center/cover no-repeat;">
		<div class="content" id="contentid" >
			<div class="login-logo" style="font-size: 35px; font-weight: bold;">
				<a href="./index.php">校园闲置物品交易系统</a>
			</div>
			<div class="login-box">
				<div class="tit">用户登录</div>
			<div>
				<form method="post" action="?" name="form1" id="form1"  onSubmit="return check();">
					<div class="input-box">
						<input class="ant-input" type="text" name="account" placeholder="用户名">
					</div>
					<div class="input-box">
						<input class="ant-input" type="password" name="password" placeholder="密码">
					</div>
					<!--新加-->
					<div class="captcha">
						<label>验证码</label>
						<input type="text" class="input" id="yan" name="code" placeholder="验证码">
						<a href="javascript:void(0)" onclick="document.getElementById('captcha_img').src = './captcha.php'">
							<img id="captcha_img" border="1" src="./image_captcha.php" alt="" width="100" height="30">
						</a>
					</div>
					<!--新加-->
					<div class="input-box">
						<button style="width:200px" type="submit"  class="login-bt ant-btn">
							<span>登 录</span>
						</button>
						<a class="fr reg-bt" href="register.php" rel="nofollow" style="color:white;">已有账户？ 去注册</a>
					</div>
				</form>
			</div>
		</div>
	</div>
</body>
</html>
<script type="text/javascript"> 
function check(){   
    if(document.form1.account.value==""){
		alert("请输入用户名");
		document.form1.account.focus();
		return false;}
	if(document.form1.password.value==""){
		alert("请输入密码");
		document.form1.password.focus();
		return false;
	}
	
}
</script>